/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.zwu.t2;

import java.math.BigDecimal;
import javax.jcr.*;
import javax.jcr.nodetype.*;
import org.apache.jackrabbit.core.TransientRepository;

/**
 *
 * @author Administrator
 */
public class ILookNode {
public static void main(String[] args) throws Exception {
        Repository repository = new TransientRepository();
        Session session = repository.login(
                new SimpleCredentials("username", "password".toCharArray()));
        try {
            Node root = session.getRootNode();

            // Store content
            Node hello = root.addNode("hello");
            Node world = hello.addNode("world");
            world.setProperty("message", "Hello, World!");
            session.save();

            // Retrieve content
            Node node = root.getNode("hello/world");
            System.out.println(node.getPath());
            System.out.println(node.getProperty("message").getString());

            mynode(session.getWorkspace());
            // Remove content

            root.getNode("hello").remove();
            session.save();
        } finally {
            session.logout();
        }
    }


    public static void mynode(Workspace wk) throws Exception
    {
        NodeTypeManager ntm = wk.getNodeTypeManager();
        NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();

        //ntt.setMixin(true);
        ntt.setName("ilooktag4");
        ntt.setDeclaredSuperTypeNames(new String[]{"nt:unstructured"});
        //ntt.setPrimaryItemName("nt:unstructured");
        ntm.registerNodeType(ntt, true);
        System.out.println(ntm.hasNodeType("ilooktag4"));
        //Node node = wk.getNamespaceRegistry().registerNamespace(, null)

      
        Node n = wk.getSession().getRootNode();
        n = n.addNode("nothing");
        //n.addMixin("ilooktag2");
        n = n.addNode("testing", "ilooktag4");

        n.setProperty("nt:file", BigDecimal.ONE);
       
        


    }

}
